class Solution {
    public int search(int[] nums, int target) {

        int left = 0;
        int right = nums.length - 1;
        while (left <= right && nums[left] < target) {
            left++;
        }
        while (left <= right && nums[right] > target) {
            right--;
        }
        return right - left + 1;

    }
}